[id].vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. <template>
  2. <!-- 页面头部 -->
  3. <HomePageHead></HomePageHead>
  4. <HomePageNavigation></HomePageNavigation>
  5. <!-- 面包屑导航 -->
  6. <div class="breadcrumb">
  7. <div class="inner">
  8. <span class="location">当前位置:</span>
  9. <el-breadcrumb :separator-icon="ArrowRight">
  10. <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
  11. <el-breadcrumb-item :to="{ path: `/primaryNavigation/${listid}` }" v-show="name">{{ name
  12. }}</el-breadcrumb-item>
  13. <el-breadcrumb-item>{{ newsDetail.con_title }}</el-breadcrumb-item>
  14. </el-breadcrumb>
  15. </div>
  16. </div>
  17. <!-- 资讯列表 -->
  18. <div class="newsDetail">
  19. <div class="inner">
  20. <div class="innerDetail">
  21. <div class="headImg"></div>
  22. <div class="innerDetail1">
  23. <div class="leftBottom" v-html="newsDetail.content"></div>
  24. </div>
  25. <div class="footImg"></div>
  26. </div>
  27. <div class="innerLeft">
  28. <ul>
  29. <li>
  30. 导航列表
  31. </li>
  32. <li v-for="(item, index) in bottomMenu" :key="index">
  33. <NuxtLink :to="`/speciaArticle/${item.id}`" v-if="item.id == pageId && item.id != 7"
  34. class="active">
  35. {{ item.name }}
  36. </NuxtLink>
  37. <NuxtLink :to="`/speciaArticle/${item.id}`" v-else-if="item.id != pageId && item.id != 7">
  38. {{item.name }}
  39. </NuxtLink>
  40. </li>
  41. </ul>
  42. </div>
  43. <div style="clear: both;"></div>
  44. </div>
  45. </div>
  46. <!-- 列表页广告一 -->
  47. <HomeTopTenTitle :imgurl="adList[0]" v-if="adList[0]"></HomeTopTenTitle>
  48. <!-- 页面底部 -->
  49. <HomeFoot1></HomeFoot1>
  50. </template>
  51. <script setup>
  52. import { onMounted } from 'vue'
  53. import { ElBreadcrumb, ElBreadcrumbItem } from 'element-plus'
  54. import { ArrowRight } from '@element-plus/icons-vue'
  55. const nuxtApp = useNuxtApp();
  56. const axios = nuxtApp.$axios;
  57. //获得跳转过来的id
  58. const route = useRoute();
  59. const articleId = route.params.id; //获得该页面的id
  60. const listid = route.query.listId; //获得该页面的id
  61. const name = route.query.listName; //获得该页面的id
  62. const pageId = route.params.id; //获得该页面的id
  63. const routeHref = route.href;
  64. console.log(333333)
  65. console.log(route.href)
  66. const newsDetail = ref({})
  67. console.log(articleId)
  68. const routeNewsTtitle = ref("");
  69. //获得广告
  70. const adList = ref("");
  71. const aa = 'page'
  72. const getadList = async () => {
  73. try {
  74. const response = await axios.get(`/web/getWebsiteAdvertisement?ad_tag=${aa}`);
  75. adList.value = response.data;
  76. } catch (error) {
  77. console.error(error);
  78. }
  79. }
  80. onMounted(() => {
  81. //获得广告
  82. getadList()
  83. })
  84. // 定义响应式数据
  85. const seoData = ref({
  86. title: '三农资讯网',
  87. description: '默认描述',
  88. keywords: '默认关键词',
  89. image: 'https://example.com/default-image.jpg'
  90. });
  91. // 在 onMounted 钩子中获取数据
  92. onMounted(async () => {
  93. try {
  94. const response = await axios.get(`/web/getWebsiteCategoryHead?catid=${articleId}`);
  95. const data = response.data.website_head; // 假设接口返回的数据在 data 字段中
  96. console.log(seoData.value.title)
  97. // 更新 seoData
  98. seoData.value = {
  99. title: data.seo_title,
  100. description: data.seo_description,
  101. keywords: data.seo_keywords,
  102. image: data.seo_image
  103. };
  104. console.log(seoData.value.title)
  105. } catch (error) {
  106. console.error('获取 SEO 数据失败:', error);
  107. // 设置默认值
  108. seoData.value = {
  109. title: '三农资讯网',
  110. description: '默认描述',
  111. keywords: '默认关键词',
  112. image: 'https://example.com/default-image.jpg'
  113. };
  114. }
  115. });
  116. // 监听 seoData 的变化,动态设置 SEO 字段
  117. watch(seoData, (newVal) => {
  118. if (newVal.title) { // 确保 title 有值
  119. useSeoMeta({
  120. title: newVal.title, // 使用动态值
  121. description: newVal.description,
  122. ogTitle: newVal.title,
  123. ogDescription: newVal.description,
  124. ogImage: newVal.image,
  125. twitterTitle: newVal.title,
  126. twitterDescription: newVal.description,
  127. twitterImage: newVal.image,
  128. keywords: newVal.keywords
  129. });
  130. }
  131. }, { immediate: true });
  132. //获取详情
  133. const getNewsInfo = async () => {
  134. const response = await axios.get(`/web/getWebsiteFooterCategoryInfo?fcat_id=${articleId}`);
  135. newsDetail.value = response.data;
  136. console.log(newsDetail.value.title)
  137. if (newsDetail.value.title.length > 30) {
  138. routeNewsTtitle.value = newsDetail.value.title.substr(0, 30) + "...";
  139. }
  140. }
  141. //获得底部导航
  142. const bottomMenu = ref([]);
  143. const getBottomMenu = async () => {
  144. const response = await axios.get(`/web/getWebsiteFooterCategory`);
  145. bottomMenu.value = response.data;
  146. }
  147. onMounted(() => {
  148. //获得详情
  149. getNewsInfo()
  150. // 获得左侧导航
  151. getBottomMenu()
  152. })
  153. </script>
  154. <style lang="less" scoped>
  155. //导航条
  156. .breadcrumb {
  157. width: 1200px;
  158. margin: 0 auto;
  159. height: 22px;
  160. padding-bottom: 40px;
  161. margin-top: 40px;
  162. margin-bottom: 60px;
  163. border-bottom: 1px solid #d9d9d9;
  164. font-family: Microsoft YaHei, Microsoft YaHei;
  165. font-weight: 400;
  166. font-size: 20px;
  167. color: #666666;
  168. line-height: 23px;
  169. text-align: left;
  170. font-style: normal;
  171. text-transform: none;
  172. .el-breadcrumb::v-deep {
  173. display: inline-block;
  174. vertical-align: -4px;
  175. }
  176. /deep/.el-breadcrumb__inner a,
  177. /deep/.el-breadcrumb__inner.is-link {
  178. color: #666666;
  179. font-weight: 400;
  180. text-decoration: none;
  181. transition: var(--el-transition-color);
  182. }
  183. span {
  184. font-family: Microsoft YaHei, Microsoft YaHei;
  185. font-weight: 400;
  186. font-size: 20px;
  187. color: #666666;
  188. line-height: 23px;
  189. text-align: left;
  190. font-style: normal;
  191. text-transform: none;
  192. }
  193. span:hover {
  194. color: #666666;
  195. }
  196. .location {
  197. margin-right: 20px;
  198. width: 100px;
  199. height: 22px;
  200. font-family: Microsoft YaHei, Microsoft YaHei;
  201. font-weight: 400;
  202. font-size: 20px;
  203. color: #666666;
  204. line-height: 23px;
  205. text-align: left;
  206. font-style: normal;
  207. text-transform: none;
  208. }
  209. }
  210. // 资讯列表
  211. .newsDetail {
  212. width: 100%;
  213. // height: 1400px;
  214. // margin-bottom: 70px;
  215. .inner {
  216. width: 1200px;
  217. font-size: 16px;
  218. position: relative;
  219. .innerDetail {
  220. width: 1080px;
  221. margin: 0 auto;
  222. margin-bottom: 60px;
  223. .headImg {
  224. width: 1086px;
  225. height: 10px;
  226. background: url("../../public/special/head11.png") no-repeat 100% 100%;
  227. }
  228. .footImg {
  229. width: 1086px;
  230. height: 7px;
  231. background: url("../../public/special/foot01.png") no-repeat 100% 100%;
  232. }
  233. .innerDetail1 {
  234. width: 1086px;
  235. margin: 0 auto;
  236. padding: 30px 50px 40px;
  237. box-sizing: border-box;
  238. border-left: 1px solid #DBBE9E;
  239. background: url("../../public/special/mid01.png") repeat-y 100% 100%;
  240. }
  241. .leftBottom::v-deep {
  242. font-size: 16px;
  243. line-height: 40px;
  244. }
  245. }
  246. .innerLeft {
  247. width: 279px;
  248. position: absolute;
  249. top: 3px;
  250. left: -155px;
  251. .rightMenuTitle {
  252. width: 279px;
  253. height: 69px;
  254. font-size: 22px;
  255. font-weight: bold;
  256. line-height: 58px;
  257. text-align: center;
  258. color: #fff;
  259. background: url("../../public/special/projectMoreTitle.png") no-repeat;
  260. margin-bottom: 30px;
  261. }
  262. ul {
  263. li {
  264. a {
  265. display: inline-block;
  266. width: 144px;
  267. height: 60px;
  268. line-height: 60px;
  269. text-align: center;
  270. background-color: #F4F4F4;
  271. border-top: 1px #fff solid;
  272. font-family: Microsoft YaHei, Microsoft YaHei;
  273. font-weight: 400;
  274. font-size: 16px;
  275. color: #000000;
  276. }
  277. }
  278. li:nth-child(1) {
  279. width: 144px;
  280. height: 60px;
  281. line-height: 60px;
  282. text-align: center;
  283. background-color: #F4F4F4;
  284. border-top: 1px #fff solid;
  285. font-family: Microsoft YaHei, Microsoft YaHei;
  286. font-weight: 400;
  287. font-size: 16px;
  288. color: #a01c0e;
  289. }
  290. }
  291. .active {
  292. // border-left: 0;
  293. // border: 1px solid #028E21;
  294. background: #a01c0e;
  295. color: #fff;
  296. }
  297. }
  298. }
  299. }
  300. </style>